# -*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name:        tests.py
# Purpose:
#
# Author:      Drago@
#
# Created:     06.08.2009
# Copyright:   (c) Drago@ 2009
# Licence:     <your licence>
#-------------------------------------------------------------------------------
#!/usr/bin/env python

from pygs.interfaces import ImplementationConfig
from pygs.serviceProvider import serviceProviderInstance

def main():
    """
        Test code
    """

    '''   
    serviceProviderInstance.changeServiceConfig("SecurityPersistence", 
                                            ImplementationConfig(
                                                                 module = "pygs.services.security.securityPersistenceInMySQLDB", 
                                                                 className = "SecurityPersistenceInMySQLDB", 
                                                                 remote = False,
                                                                 remoteAddress = "PYRO://10.27.11.43:7777/services", 
                                                                 params = None))    
    
     
    serviceProviderInstance.registerService("SecurityPersistence", 
                                            ImplementationConfig(
                                                                 module = "pygs.services.security.securityPersistenceInMemory", 
                                                                 className = "SecurityPersistenceInMemory", 
                                                                 remote = True,
                                                                 remoteAddress = "PYRO://10.27.11.43:7777/0a1b0b2b1efc30ac962e0160029ba382", 
                                                                 params = None))
    serviceProviderInstance.registerService("Authentication", 
                                            ImplementationConfig(
                                                                 module = "pygs.services.security.authenticationSecured", 
                                                                 className = "AuthenticationSecured", 
                                                                 remote = False,
                                                                 remoteAddress = "", 
                                                                 params = None)) 
    
    serviceProviderInstance.registerService("Authorization", 
                                            ImplementationConfig(
                                                                 module = "pygs.services.security.authorizationSimple", 
                                                                 className = "AuthorizationSimple", 
                                                                 remote = False,
                                                                 remoteAddress = "", 
                                                                 params = None))     
    '''

    tokenInfo = serviceProviderInstance.implementation("Authentication").login("lp", {"user": "user1", "passwd": "11111"})    
    print "user 1 tokenInfo: %s" % tokenInfo
    
    token = tokenInfo["token"]
    print "user 1 token: %s" % token
    
    print "getLogedIn: %s" % serviceProviderInstance.implementation("Authorization").getLogedIn(token) 
    print "getUserId: %s" % serviceProviderInstance.implementation("Authorization").getUserId(token)

    logoutRes = serviceProviderInstance.implementation("Authentication").logout(token)
    print "logout result: %s" % logoutRes

    print "getLogedIn: %s" % serviceProviderInstance.implementation("Authorization").getLogedIn(token) 
    print "getUserId: %s" % serviceProviderInstance.implementation("Authorization").getUserId(token)

    tokenInfo = serviceProviderInstance.implementation("Authentication").login("lp", {"user": "user2", "passwd": "11111"})    
    print "user 2 tokenInfo: %s" % tokenInfo

    tokenInfo = serviceProviderInstance.implementation("Authentication").login("lp", {"user": "user3", "passwd": "11111"})    
    print "user 3 tokenInfo: %s" % tokenInfo
    
if __name__ == '__main__':
    main()


